package com.ldk.api;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ldk.base.framework.util.DateUtil;
import com.ldk.base.framework.util.HttpUtil;
import com.ldk.base.framework.util.SystemUtil;
import com.ldk.framework.entity.Company;
import com.ldk.framework.entity.Companyfare;
import com.ldk.framework.entity.Companypay;
import com.ldk.framework.entity.Companypermit;
import com.ldk.framework.entity.Companyservice;
import com.ldk.framework.entity.Companystat;
import com.ldk.framework.entity.Driver;
import com.ldk.framework.entity.Driverapp;
import com.ldk.framework.entity.Drivereducate;
import com.ldk.framework.entity.Driverstat;
import com.ldk.framework.entity.OperateArrive;
import com.ldk.framework.entity.OperateDepart;
import com.ldk.framework.entity.OperateLogin;
import com.ldk.framework.entity.OperateLogout;
import com.ldk.framework.entity.OperatePay;
import com.ldk.framework.entity.OrderCancel;
import com.ldk.framework.entity.OrderCreate;
import com.ldk.framework.entity.OrderMatch;
import com.ldk.framework.entity.Passenger;
import com.ldk.framework.entity.PlatformDriver;
import com.ldk.framework.entity.PositionDriver;
import com.ldk.framework.entity.PositionVehicle;
import com.ldk.framework.entity.RatedDriver;
import com.ldk.framework.entity.RatedDriverpunish;
import com.ldk.framework.entity.RatedPassenger;
import com.ldk.framework.entity.RatedPassengercomplaint;
import com.ldk.framework.entity.ServiceTrip;
import com.ldk.framework.entity.User;
import com.ldk.framework.entity.Vehicle;
import com.ldk.framework.entity.Vehicleinsurance;
import com.ldk.framework.entity.Vehicletotalmile;
import com.ldk.framework.enums.PlatformUserType;
import com.ldk.framework.enums.ServiceCode;
import com.ldk.framework.enums.TripStatus;
import com.ldk.framework.service.ICJTServiceTripService;
import com.ldk.framework.service.ICompanyService;
import com.ldk.framework.service.ICompanyfareService;
import com.ldk.framework.service.ICompanypayService;
import com.ldk.framework.service.ICompanypermitService;
import com.ldk.framework.service.ICompanyserviceService;
import com.ldk.framework.service.ICompanystatService;
import com.ldk.framework.service.IDriverService;
import com.ldk.framework.service.IDriverappService;
import com.ldk.framework.service.IDrivereducateService;
import com.ldk.framework.service.IDriverstatService;
import com.ldk.framework.service.IOperateArriveService;
import com.ldk.framework.service.IOperateDepartService;
import com.ldk.framework.service.IOperateLoginService;
import com.ldk.framework.service.IOperateLogoutService;
import com.ldk.framework.service.IOperatePayService;
import com.ldk.framework.service.IOrderCancelService;
import com.ldk.framework.service.IOrderCreateService;
import com.ldk.framework.service.IOrderMatchService;
import com.ldk.framework.service.IPassengerService;
import com.ldk.framework.service.IPhoneValidcodeService;
import com.ldk.framework.service.IPlatformDriverService;
import com.ldk.framework.service.IPositionDriverService;
import com.ldk.framework.service.IPositionVehicleService;
import com.ldk.framework.service.IRatedDriverService;
import com.ldk.framework.service.IRatedDriverpunishService;
import com.ldk.framework.service.IRatedPassengerService;
import com.ldk.framework.service.IRatedPassengercomplaintService;
import com.ldk.framework.service.IServiceTripService;
import com.ldk.framework.service.IUserService;
import com.ldk.framework.service.IVehicleService;
import com.ldk.framework.service.IVehicleinsuranceService;
import com.ldk.framework.service.IVehicletotalmileService;

import org.apache.http.util.TextUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class TimePushTask {

    private final Logger logger = LoggerFactory.getLogger(TimePushTask.class);
    @Autowired
    private ICompanypermitService companypermitService;
    @Autowired
    private ICompanyService companyService;
    @Autowired
    private ICompanystatService companystatService;
    @Autowired
    private ICompanypayService companypayService;
    @Autowired
    private ICompanyfareService companyfareService;
    @Autowired
    private ICompanyserviceService companyserviceService;
    @Autowired
    private IVehicleService vehicleService;
    @Autowired
    private IVehicleinsuranceService vehicleinsuranceService;
    @Autowired
    private IVehicletotalmileService vehicletotalmileService;
    @Autowired
    private IPlatformDriverService platformDriverService;
    @Autowired
    private IDriverService driverService;
    @Autowired
    private IDrivereducateService drivereducateService;
    @Autowired
    private IDriverappService driverappService;
    @Autowired
    private IDriverstatService driverstatService;
    @Autowired
    private IPassengerService passengerService;
    @Autowired
    private IUserService userService;
    @Autowired
    private IOrderCreateService orderCreateService;
    @Autowired
    private IOrderCancelService orderCancelService;
    @Autowired
    private IOrderMatchService orderMatchService;
    @Autowired
    private IOperatePayService operatePayService;

    @Autowired
    private IOperateLoginService operateLoginService;
    @Autowired
    private IOperateLogoutService operateLogoutService;
    @Autowired
    private IOperateDepartService operateDepartService;
    @Autowired
    private IOperateArriveService operateArriveService;

    @Autowired
    private IPositionDriverService positionDriverService;
    @Autowired
    private IPositionVehicleService positionVehicleService;
    @Autowired
    private IRatedPassengerService ratedPassengerService;
    @Autowired
    private IRatedDriverpunishService ratedDriverpunishService;
    @Autowired
    private IRatedPassengercomplaintService ratedPassengercomplaintService;
    @Autowired
    private IRatedDriverService ratedDriverService;

    private String posturl = "https://data.yycjg.com";

    /**
     * quartz 表达式定时执行方法
     */
    public void cronExcutePush() {
        logger.error("每隔1小时推送一次数据，开始执行");

        baseinfoCompany();
        baseinfoCompanyStat();
        baseinfoCompanyPay();
        baseinfoCompanyService();
        baseinfoCompanyPermit();
        baseinfoCompanyFare();

        baseinfoVehicle();
        baseinfoVehicleInsurance();
        baseinfoVehicleTotalMile();
        baseinfoDriver();
        baseinfoDriverEducate();
        baseinfoDriverApp();
        baseinfoDriverStat();
        baseinfoPassenger();

        orderCreate();
        orderMatch();
        orderCancel();

        operateLogin();
        operateLogout();
        operateDepart();
        operateArrive();
        operatePay();

        positionDriver();
        positionVehicle();

        ratedPassenger();
        ratedPassengerComplaint();
        ratedDriverPunish();
        ratedDriver();
    }

    /**
     * 网约车平台公司基本信息
     */
    public boolean baseinfoCompany() {
        String url = "/baseinfo/company";
        String method = "baseinfoCompany";
        JSONArray jsonArray = new JSONArray();

        Date date = new Date();

        Company query = new Company();
        query.setCompanyId("5201HDCX8779");
        Company company = companyService.selectOne(null, query);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("CompanyId", company.getCompanyId());
        jsonObject.put("CompanyName", company.getCompanyName());
        jsonObject.put("Identifier", company.getIdentifier());
        jsonObject.put("Address", company.getAddress());
        jsonObject.put("BusinessScope", company.getBusinessScope());
        jsonObject.put("ContactAddress", company.getContactAddress());
        jsonObject.put("EconomicType", company.getEconomicType());
        jsonObject.put("RegCapital", company.getRegCapital());
        jsonObject.put("LegalName", company.getLegalName());
        jsonObject.put("LegalID", company.getLegalID());
        jsonObject.put("LegalPhone", company.getLegalPhone());
        //jsonObject.put("LegalPhoto", company.getLegalPhoto() );
        jsonObject.put("State", company.getState());
        jsonObject.put("Flag", company.getFlag());
        jsonObject.put("UpdateTime", DateUtil.DatetoString(date, "yyyyMMddHHmmss"));
        jsonArray.add(jsonObject);
        boolean success = pushData(jsonArray, url, method);
        return success;
    }


    /**
     * 网约车平台公司营运规模信息
     */
    public boolean baseinfoCompanyStat() {
        String url = "/baseinfo/companystat";
        String method = "baseinfoCompanyStat";
        JSONArray jsonArray = new JSONArray();

        Date date = new Date();

        Companystat query = new Companystat();
        query.setCompanyId("5201HDCX8779");
        Companystat company = companystatService.selectOne(null, query);

        //查询车子数量
        List<Vehicle> list = vehicleService.selectAll(null);
        //查询司机数量
        List<Driver> list1 = driverService.selectAll(null);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("CompanyId", company.getCompanyId());
        //jsonObject.put("VehicleNum", company.getVehicleNum());
        //jsonObject.put("DriverNum", company.getDriverNum());
        jsonObject.put("VehicleNum", list.size());
        jsonObject.put("DriverNum", list1.size());
        jsonObject.put("Flag", company.getFlag());
        jsonObject.put("UpdateTime", DateUtil.DatetoString(date, "yyyyMMddHHmmss"));
        jsonArray.add(jsonObject);

        boolean success = pushData(jsonArray, url, method);
        return success;
    }


    /**
     * 网约车平台公司支付信息
     */
    public boolean baseinfoCompanyPay() {
        String url = "/baseinfo/companypay";
        String method = "baseinfoCompanyPay";
        JSONArray jsonArray = new JSONArray();

        Date date = new Date();

        Companypay query = new Companypay();
        query.setCompanyId("5201HDCX8779");
        Companypay company = companypayService.selectOne(null, query);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("CompanyId", company.getCompanyId());
        jsonObject.put("PayName", company.getPayName());
        jsonObject.put("PayId", company.getPayId());
        jsonObject.put("PayType", company.getPayType());
        jsonObject.put("PayScope", company.getPayScope());
        jsonObject.put("PrepareBank", company.getPrepareBank());
        jsonObject.put("CountDate", company.getCountDate());
        jsonObject.put("State", company.getState());
        jsonObject.put("Flag", company.getFlag());
        jsonObject.put("UpdateTime", DateUtil.DatetoString(date, "yyyyMMddHHmmss"));
        jsonArray.add(jsonObject);
        boolean success = pushData(jsonArray, url, method);
        return success;
    }

    /**
     * 网约车平台公司服务机构
     */
    public boolean baseinfoCompanyService() {
        String url = "/baseinfo/companyservice";
        String method = "baseinfoCompanyService";
        JSONArray jsonArray = new JSONArray();

        Date date = new Date();
        List<Companyservice> list = companyserviceService.selectAll(null);
        for (Companyservice company : list) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", company.getCompanyId());
            jsonObject.put("Address", company.getAddress());
            jsonObject.put("ServiceName", company.getServiceName());
            jsonObject.put("ServiceNo", company.getServiceNo());
            jsonObject.put("DetailAddress", company.getDetailAddress());
            jsonObject.put("ResponsibleName", company.getResponsibleName());
            jsonObject.put("ResponsiblePhone", company.getResponsiblePhone());
            jsonObject.put("ManagerName", company.getManagerName());
            jsonObject.put("ManagerPhone", company.getManagerPhone());
            jsonObject.put("ContactPhone", company.getContactPhone());
            jsonObject.put("MailAddress", company.getMailAddress());
            jsonObject.put("CreateDate", company.getCreateDate());
            jsonObject.put("ResponsiblePhone", company.getResponsiblePhone());
            jsonObject.put("State", company.getState());
            jsonObject.put("Flag", company.getFlag());
            jsonObject.put("UpdateTime", DateUtil.DatetoString(date, "yyyyMMddHHmmss"));
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        return success;
    }

    /**
     * 网约车平台公司经营许可
     */
    public boolean baseinfoCompanyPermit() {
        String url = "/baseinfo/companypermit";
        String method = "baseinfoCompanyPermit";
        JSONArray jsonArray = new JSONArray();
        Date date = new Date();
        List<Companypermit> list = companypermitService.selectAll("");
        for (Companypermit companypermit : list) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("Address", Integer.parseInt(companypermit.getAddress()));
            jsonObject.put("Certificate", companypermit.getCertificate());
            jsonObject.put("OperationArea", companypermit.getOperationArea());
            jsonObject.put("OwnerName", companypermit.getOwnerName());
            jsonObject.put("Organization", companypermit.getOrganization());
            jsonObject.put("StartDate", Integer.parseInt(companypermit.getStartDate()));
            jsonObject.put("StopDate", Integer.parseInt(companypermit.getStopDate()));
            jsonObject.put("CertifyDate", Integer.parseInt(companypermit.getCertifyDate()));
            jsonObject.put("State", companypermit.getState());
            jsonObject.put("Flag", Integer.parseInt(companypermit.getFlag() + ""));
            jsonObject.put("UpdateTime", DateUtil.DatetoString(new Date(), "yyyyMMddHHmmss"));
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        return success;
    }

    /**
     * 网约车平台公司运价信息
     */
    public boolean baseinfoCompanyFare() {
        String url = "/baseinfo/companyfare";
        String method = "baseinfoCompanyFare";
        JSONArray jsonArray = new JSONArray();
        Date date = new Date();
        List<Companyfare> list = companyfareService.selectAll(null);
        for (Companyfare companypermit : list) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("Address", Integer.parseInt(companypermit.getAddress()));
            jsonObject.put("FareType", companypermit.getFareType());
            jsonObject.put("FareTypeNote", companypermit.getFareTypeNote());
            jsonObject.put("FareValidOn", companypermit.getFareValidOn());
            jsonObject.put("FareValidOff", companypermit.getFareValidOff());
            jsonObject.put("StartFare", companypermit.getStartFare());
            jsonObject.put("StartMile", companypermit.getStartMile());
            jsonObject.put("UnitPricePerMile", companypermit.getUnitPricePerMile());
            jsonObject.put("UpPrice", companypermit.getUpPrice());
            jsonObject.put("MorningPeakTimeOn", companypermit.getMorningPeakTimeOn());
            jsonObject.put("MorningPeakTimeOff", companypermit.getMorningPeakTimeOff());
            jsonObject.put("EveningPeakTimeOn", companypermit.getEveningPeakTimeOn());
            jsonObject.put("EveningPeakTimeOff", companypermit.getEveningPeakTimeOff());
            jsonObject.put("OtherPeakTimeOn", companypermit.getOtherPeakTimeOn());
            jsonObject.put("OtherPeakTimeOff", companypermit.getOtherPeakTimeOff());
            jsonObject.put("PeakUnitPrice", companypermit.getPeakUnitPrice());
            jsonObject.put("PeakPriceStartMile", companypermit.getPeakPriceStartMile());
            jsonObject.put("LowSpeedPricePerMinute", companypermit.getLowSpeedPricePerMinute());
            jsonObject.put("NightPricePerMile", companypermit.getUnitPricePerMile());
            jsonObject.put("NightPricePerMinute", companypermit.getNightPricePerMinute());
            jsonObject.put("OtherPrice", companypermit.getOtherPrice());
            jsonObject.put("State", companypermit.getState());
            jsonObject.put("Flag", companypermit.getFlag());
            jsonObject.put("UpdateTime", DateUtil.DatetoString(new Date(), "yyyyMMddHHmmss"));
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        return success;
    }

    /**
     * 车辆基本信息接口定义
     */
    public boolean baseinfoVehicle() {
        String url = "/baseinfo/vehicle";
        String method = "baseinfoVehicle";
        JSONArray jsonArray = new JSONArray();
        Date date = new Date();
        Vehicle query = new Vehicle();
        query.setUploadFlag(0);
        List<Vehicle> list = vehicleService.selectList(null, query);
        logger.error("查询到车辆基本信息上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            Vehicle companypermit = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("Address", companypermit.getAddress());
            jsonObject.put("VehicleNo", companypermit.getVehicleNo());
            jsonObject.put("PlateColor", companypermit.getPlateColor());
            jsonObject.put("Seats", companypermit.getSeats());
            jsonObject.put("Brand", companypermit.getBrand());
            jsonObject.put("Model", companypermit.getModel());
            jsonObject.put("VehicleType", companypermit.getVehicleType());
            jsonObject.put("OwnerName", companypermit.getOwnerName());
            jsonObject.put("VehicleColor", companypermit.getVehicleColor());
            jsonObject.put("EngineId", companypermit.getEngineId());
            jsonObject.put("VIN", companypermit.getVIN());
            jsonObject.put("CertifyDateA", companypermit.getCertifyDateA());
            jsonObject.put("FuelType", companypermit.getFuelType());
            jsonObject.put("EngineDisplace", companypermit.getEngineDisplace());
            //jsonObject.put("PhotoId", companypermit.getPhotoId());
            //jsonObject.put("Certificate", companypermit.getCertificate());
            jsonObject.put("TransAgency", companypermit.getTransAgency());
            jsonObject.put("TransArea", companypermit.getTransArea());
            jsonObject.put("TransDateStart", companypermit.getTransDateStart());
            jsonObject.put("CertifyDateB", companypermit.getCertifyDateB());
            jsonObject.put("FixState", companypermit.getFixState());
            //jsonObject.put("NextFixDate", companypermit.getNextFixDate());
            jsonObject.put("CheckState", companypermit.getCheckState());
            jsonObject.put("FeePrintId", companypermit.getFeePrintId());
            jsonObject.put("GPSBrand", companypermit.getGPSBrand());
            jsonObject.put("GPSModel", companypermit.getGPSModel());
            jsonObject.put("GPSIMEI", companypermit.getGPSIMEI());
            jsonObject.put("GPSInstallDate", companypermit.getGPSInstallDate());
            jsonObject.put("RegisterDate", companypermit.getRegisterDate());
            jsonObject.put("CommercialType", companypermit.getCommercialType());
            jsonObject.put("FareType", companypermit.getFareType());
            jsonObject.put("State", companypermit.getState());
            jsonObject.put("Flag", companypermit.getFlag());
            jsonObject.put("UpdateTime", DateUtil.DatetoString(new Date(), "yyyyMMddHHmmss"));
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            List<PlatformDriver> driverlist = platformDriverService.selectAll(null);
            logger.error("上传成功，更新车辆基本信息为已上传");
            for (int i = 0; i < list.size(); i++) {
                Vehicle companypermit = list.get(i);
                companypermit.setFlag(2L);
                companypermit.setUploadFlag(1);
                vehicleService.updateByKey("", companypermit);
                putToGJ(companypermit, driverlist);
            }
        }
        return success;
    }

    /**
     * 车辆保险信息接口
     */
    public boolean baseinfoVehicleInsurance() {
        String url = "/baseinfo/vehicleinsurance";
        String method = "baseinfoVehicleInsurance";
        JSONArray jsonArray = new JSONArray();
        Date date = new Date();
        Vehicleinsurance query = new Vehicleinsurance();
        query.setUpdateTime2(0L);
        List<Vehicleinsurance> list = vehicleinsuranceService.selectListUpper(null, query);
        logger.error("查询到车辆保险信息接口上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            Vehicleinsurance companypermit = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("VehicleNo", companypermit.getVehicleNo());
            jsonObject.put("InsurCom", companypermit.getInsurCom());
            jsonObject.put("InsurNum", companypermit.getInsurNum());
            jsonObject.put("InsurType", companypermit.getInsurType());
            jsonObject.put("InsurCount", companypermit.getInsurCount());
            jsonObject.put("InsurEff", companypermit.getInsurEff());
            jsonObject.put("InsurExp", companypermit.getInsurExp());
            jsonObject.put("Flag", companypermit.getFlag());
            jsonObject.put("UpdateTime", companypermit.getUpdateTime());
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，更新车辆保险信息为已上传");
            for (int i = 0; i < list.size(); i++) {
                Vehicleinsurance companypermit = list.get(i);
                companypermit.setFlag(2L);
                companypermit.setUpdateTime2(1L);
                vehicleinsuranceService.updateUpperByKey("", companypermit);
            }
        }
        return success;
    }

    /**
     * 网约车车辆里程信息
     */
    public boolean baseinfoVehicleTotalMile() {
        String url = "/baseinfo/vehicletotalmile";
        String method = "baseinfoVehicleTotalMile";
        JSONArray jsonArray = new JSONArray();
        Vehicletotalmile query = new Vehicletotalmile();
        query.setUpdateTime2(0L);
        List<Vehicletotalmile> list = vehicletotalmileService.selectListUpper(null, query);
        logger.error("查询到网约车车辆里程信息接口上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            Vehicletotalmile companypermit = list.get(i);
            companypermit.setVehicleNo(companypermit.getVehicleNo());
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("Address", companypermit.getAddress());
            jsonObject.put("VehicleNo", companypermit.getVehicleNo());
            jsonObject.put("TotalMile", companypermit.getTotalMile());
            jsonObject.put("Flag", companypermit.getFlag());
            jsonObject.put("UpdateTime", DateUtil.DatetoString(new Date(), "yyyyMMddHHmmss"));
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，网约车车辆里程信息为已上传");
            for (int i = 0; i < list.size(); i++) {
                Vehicletotalmile companypermit = list.get(i);
                companypermit.setFlag(2L);
                companypermit.setUpdateTime2(1L);
                vehicletotalmileService.updateUpperByKey("", companypermit);
            }
        }
        return success;
    }

    /**
     * 驾驶员基本信息接口
     */
    public boolean baseinfoDriver() {
        String url = "/baseinfo/driver";
        String method = "baseinfoDriver";
        JSONArray jsonArray = new JSONArray();
        Date date = new Date();
        PlatformDriver query = new PlatformDriver();
        query.setEnabled(false);
        List<PlatformDriver> list = platformDriverService.selectList(null, query);
        logger.error("查询到驾驶员基本信息接口上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            PlatformDriver companypermit = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("Address", companypermit.getAddress());
            jsonObject.put("DriverName", companypermit.getDriverName());
            jsonObject.put("DriverPhone", companypermit.getDriverPhone());
            jsonObject.put("DriverGender", companypermit.getDriverGender());
            jsonObject.put("DriverBirthday", companypermit.getDriverBirthday());
            jsonObject.put("DriverNationality", companypermit.getDriverNationality());
            jsonObject.put("DriverNation", companypermit.getDriverNation());
            jsonObject.put("DriverMaritalStatus", companypermit.getDriverMaritalStatus());
            jsonObject.put("DriverLanguageLevel", companypermit.getDriverLanguageLevel());
            jsonObject.put("DriverEducation", companypermit.getDriverEducation());
            jsonObject.put("DriverCensus", companypermit.getDriverCensus());
            jsonObject.put("DriverAddress", companypermit.getDriverAddress());
            jsonObject.put("DriverContactAddress", companypermit.getDriverContactAddress());
            //jsonObject.put("PhotoId", companypermit.getPhotoId());
            jsonObject.put("LicenseId", companypermit.getLicenseId());
            //jsonObject.put("LicensePhotoId", companypermit.getLicensePhotoId());
            jsonObject.put("DriverType", companypermit.getDriverType());
            jsonObject.put("GetDriverLicenseDate", companypermit.getGetDriverLicenseDate());
            jsonObject.put("DriverLicenseOn", companypermit.getDriverLicenseOn());
            jsonObject.put("DriverLicenseOff", companypermit.getDriverLicenseOff());
            jsonObject.put("TaxiDriver", companypermit.getTaxiDriver());
            jsonObject.put("CertificateNo", companypermit.getCertificateNo());
            jsonObject.put("NetworkCarIssueOrganization", companypermit.getNetworkCarIssueOrganization());
            jsonObject.put("NetworkCarIssueDate", companypermit.getNetworkCarIssueDate());
            jsonObject.put("GetNetworkCarProofDate", companypermit.getGetNetworkCarProofDate());
            jsonObject.put("NetworkCarProofOn", companypermit.getNetworkCarProofOn());
            jsonObject.put("NetworkCarProofOff", companypermit.getNetworkCarProofOff());
            jsonObject.put("RegisterDate", companypermit.getRegisterDate());
            jsonObject.put("FullTimeDriver", companypermit.getFullTimeDriver());
            jsonObject.put("InDriverBlacklist", companypermit.getInDriverBlacklist());
            jsonObject.put("CommercialType", companypermit.getCommercialType());
            jsonObject.put("ContractCompany", companypermit.getContractCompany());
            jsonObject.put("ContractOn", companypermit.getContractOn());
            jsonObject.put("ContractOff", companypermit.getContractOff());
            jsonObject.put("EmergencyContact", companypermit.getEmergencyContact());
            jsonObject.put("EmergencyContactPhone", companypermit.getEmergencyContactPhone());
            jsonObject.put("EmergencyContactAddress", companypermit.getEmergencyContactAddress());
            jsonObject.put("State", companypermit.getState());
            jsonObject.put("Flag", companypermit.getFlag());
            jsonObject.put("UpdateTime", DateUtil.DatetoString(new Date(), "yyyyMMddHHmmss"));
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，驾驶员基本信息为已上传");
            for (int i = 0; i < list.size(); i++) {
                PlatformDriver companypermit = list.get(i);
                companypermit.setFlag(2L);
                companypermit.setEnabled(true);
                platformDriverService.updateByKey("", companypermit);
            }
        }
        return success;
    }

    /**
     * 网约车驾驶员培训信息
     */
    public boolean baseinfoDriverEducate() {
        String url = "/baseinfo/drivereducate";
        String method = "baseinfoDriverEducate";
        JSONArray jsonArray = new JSONArray();
        Date date = new Date();
        Drivereducate query = new Drivereducate();
        query.setUpdateTime2(0L);
        List<Drivereducate> list = drivereducateService.selectListUpper(null, query);
        logger.error("查询到网约车驾驶员培训信息接口上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            Drivereducate companypermit = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("Address", companypermit.getAddress());
            jsonObject.put("LicenseId", companypermit.getLicenseId());
            jsonObject.put("CourseName", companypermit.getCourseName());
            jsonObject.put("CourseDate", companypermit.getCourseDate());
            jsonObject.put("StartTime", companypermit.getStartTime1());
            jsonObject.put("StopTime", companypermit.getStopTime());
            jsonObject.put("Duration", companypermit.getDuration());
            jsonObject.put("Flag", companypermit.getFlag());
            jsonObject.put("UpdateTime", companypermit.getUpdateTime());
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，网约车驾驶员培训信息为已上传");
            for (int i = 0; i < list.size(); i++) {
                Drivereducate companypermit = list.get(i);
                companypermit.setFlag(2L);
                companypermit.setUpdateTime2(1L);
                drivereducateService.updateUpperByKey("", companypermit);
            }
        }
        return success;
    }

    /**
     * 驾驶员移动终端信息接口
     */
    public boolean baseinfoDriverApp() {
        String url = "/baseinfo/driverapp";
        String method = "baseinfoDriverApp";
        JSONArray jsonArray = new JSONArray();
        Date date = new Date();

        Driverapp query = new Driverapp();
        query.setUpdateTime2(0L);
        List<Driverapp> list = driverappService.selectListUpper(null, query);
        logger.error("查询到驾驶员移动终端信息接口接口上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            Driverapp companypermit = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("Address", companypermit.getAddress());
            jsonObject.put("LicenseId", companypermit.getLicenseId());
            jsonObject.put("DriverPhone", companypermit.getDriverPhone());
            jsonObject.put("NetType", companypermit.getNetType());
            jsonObject.put("MapType", companypermit.getMapType());
            jsonObject.put("State", companypermit.getState());
            jsonObject.put("Flag", companypermit.getFlag());
            jsonObject.put("UpdateTime", companypermit.getUpdateTime());
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，驾驶员移动终端信息接口为已上传");
            for (int i = 0; i < list.size(); i++) {
                Driverapp companypermit = list.get(i);
                companypermit.setFlag(2L);
                companypermit.setUpdateTime2(1L);
                driverappService.updateUpperByKey("", companypermit);
            }
        }
        return success;
    }

    /**
     * 网约车驾驶员统计信息
     */
    public boolean baseinfoDriverStat() {
        String url = "/baseinfo/driverstat";
        String method = "baseinfoDriverStat";
        JSONArray jsonArray = new JSONArray();
        Date date = new Date();

        Driverstat query = new Driverstat();
        query.setUpdateTime2(0L);
        List<Driverstat> list = driverstatService.selectListUpper(null, query);
        logger.error("查询到网约车驾驶员统计信息接口接口上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            Driverstat companypermit = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("Address", companypermit.getAddress());
            jsonObject.put("LicenseId", companypermit.getLicenseId());
            jsonObject.put("Cycle", companypermit.getCycle());
            jsonObject.put("OrderCount", companypermit.getOrderCount());
            jsonObject.put("TrafficViolationCount", companypermit.getTrafficViolationCount());
            jsonObject.put("ComplainedCount", companypermit.getComplainedCount());
            jsonObject.put("Flag", companypermit.getFlag());
            jsonObject.put("UpdateTime", companypermit.getUpdateTime());
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，网约车驾驶员统计信息接口为已上传");
            for (int i = 0; i < list.size(); i++) {
                Driverstat companypermit = list.get(i);
                companypermit.setFlag(2L);
                companypermit.setUpdateTime2(1L);
                driverstatService.updateUpperByKey("", companypermit);
            }
        }
        return success;
    }

    /**
     * 乘客基本信息
     */
    public boolean baseinfoPassenger() {
        String url = "/baseinfo/passenger";
        String method = "baseinfoPassenger";
        JSONArray jsonArray = new JSONArray();

        User query = new User();
        query.setUploadFlag(0);
        List<User> list = userService.selectList(null, query);
        logger.error("查询到乘客基本信息上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            User companypermit = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", "5201HDCX8779");
            Date registerDate = new Date();
            if (companypermit.getRegisterTime() != null && companypermit.getRegisterTime() > 0) {
                registerDate = new Date(companypermit.getRegisterTime() * 1000);
            }
            jsonObject.put("Area", "520100");
            jsonObject.put("RegisterDate", DateUtil.DatetoString(registerDate, "yyyyMMdd"));
            jsonObject.put("PassengerPhone", companypermit.getPhoneNo());
            jsonObject.put("PassengerName", companypermit.getNickName());
            jsonObject.put("State", 0);
            jsonObject.put("Flag", 1);
            jsonObject.put("UpdateTime", DateUtil.DatetoString(new Date(), "yyyyMMddHHmmss"));
            jsonArray.add(jsonObject);

        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，乘客基本信息为已上传");
            for (int i = 0; i < list.size(); i++) {
                User companypermit = list.get(i);
                companypermit.setUploadFlag(1);
                userService.updateByKey("", companypermit);
            }
        }
        return success;
    }

    /**
     * 订单发起接口
     */
    public boolean orderCreate() {
        String url = "/order/create";
        String method = "orderCreate";
        JSONArray jsonArray = new JSONArray();

        OrderCreate query = new OrderCreate();
        query.setOrderTime2(0L);
        List<OrderCreate> list = orderCreateService.selectListUpper(null, query);
        logger.error("查询到订单发起接口上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            OrderCreate companypermit = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("Address", companypermit.getAddress());
            jsonObject.put("DestAddress", companypermit.getDestAddress());
            jsonObject.put("OrderId", companypermit.getOrderId());
            jsonObject.put("DepartTime", companypermit.getDepartTime());
            jsonObject.put("OrderTime", companypermit.getOrderTime());
            jsonObject.put("PassengerNote", companypermit.getPassengerNote());
            jsonObject.put("Departure", companypermit.getDeparture());
            jsonObject.put("DepLongitude", companypermit.getDepLongitude());
            jsonObject.put("DepLatitude", companypermit.getDepLatitude());
            jsonObject.put("Destination", companypermit.getDestination());
            jsonObject.put("DestLatitude", companypermit.getDestLatitude());
            jsonObject.put("DestLongitude", companypermit.getDestLongitude());
            jsonObject.put("Encrypt", companypermit.getEncrypt());
            jsonObject.put("FareType", companypermit.getFareType());
            jsonObject.put("PassengerName", companypermit.getPassengerName());
            jsonObject.put("PassengerPhone", companypermit.getPassengerPhone());
            jsonObject.put("PassengerGender", companypermit.getPassengerGender());
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，订单发起接口接口为已上传");
            for (int i = 0; i < list.size(); i++) {
                OrderCreate companypermit = list.get(i);
                companypermit.setOrderTime2(1L);
                orderCreateService.updateUpperByKey("", companypermit);
            }
        }
        return success;
    }

    /**
     * 订单成功
     */
    public boolean orderMatch() {
        String url = "/order/match";
        String method = "orderMatch";
        JSONArray jsonArray = new JSONArray();

        OrderMatch query = new OrderMatch();
        query.setDistributeTime2(0L);
        List<OrderMatch> list = orderMatchService.selectListUpper(null, query);
        logger.error("查询到订单成功接口上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            OrderMatch companypermit = list.get(i);
            //for (OrderMatch companypermit : list) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("Address", companypermit.getAddress());
            jsonObject.put("OrderId", companypermit.getOrderId());
            //jsonObject.put("OrderId", companypermit.getOrderId());
            jsonObject.put("Longitude", companypermit.getLongitude());
            jsonObject.put("Latitude", companypermit.getLatitude());
            jsonObject.put("Encrypt", companypermit.getEncrypt());
            jsonObject.put("LicenseId", companypermit.getLicenseId());
            jsonObject.put("DriverPhone", companypermit.getDriverPhone());
            jsonObject.put("VehicleNo", companypermit.getVehicleNo());
            jsonObject.put("DistributeTime", companypermit.getDistributeTime());
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，订单成功接口为已上传");
            for (int i = 0; i < list.size(); i++) {
                OrderMatch companypermit = list.get(i);
                companypermit.setDistributeTime2(1L);
                orderMatchService.updateUpperByKey("", companypermit);
            }
        }
        return success;
    }

    /**
     * 订单撤销接口
     */
    public boolean orderCancel() {
        String url = "/order/cancel";
        String method = "orderCancel";
        JSONArray jsonArray = new JSONArray();

        OrderCancel query = new OrderCancel();
        query.setCancelTime2(0L);
        List<OrderCancel> list = orderCancelService.selectListUpper(null, query);
        logger.error("查询到订单撤销接口上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            OrderCancel companypermit = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("Address", companypermit.getAddress());
            jsonObject.put("OrderId", companypermit.getOrderId());
            jsonObject.put("OrderTime", companypermit.getOrderTime());
            jsonObject.put("CancelTime", companypermit.getCancelTime());
            jsonObject.put("Operator", companypermit.getOperator());
            jsonObject.put("CancelTypeCode", companypermit.getCancelTypeCode());
            jsonObject.put("CancelReason", companypermit.getCancelReason());
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，订单撤销接口为已上传");
            for (int i = 0; i < list.size(); i++) {
                OrderCancel companypermit = list.get(i);
                companypermit.setCancelTime2(1L);
                orderCancelService.updateUpperByKey("", companypermit);
            }
        }
        return success;
    }

    /**
     * 车辆经营上线接口
     */
    public boolean operateLogin() {
        String url = "/operate/login";
        String method = "operateLogin";
        JSONArray jsonArray = new JSONArray();

        OperateLogin query = new OperateLogin();
        query.setLoginTime2(0L);
        List<OperateLogin> list = operateLoginService.selectListUpper(null, query);
        logger.error("查询到车辆经营上线接口上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            OperateLogin companypermit = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("LicenseId", companypermit.getLicenseId());
            jsonObject.put("VehicleNo", companypermit.getVehicleNo());
            jsonObject.put("LoginTime", companypermit.getLoginTime());
            jsonObject.put("Longitude", companypermit.getLongitude());
            jsonObject.put("Latitude", companypermit.getLatitude());
            jsonObject.put("Encrypt", companypermit.getEncrypt());
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，车辆经营上线接口为已上传");
            for (int i = 0; i < list.size(); i++) {
                OperateLogin companypermit = list.get(i);
                companypermit.setLoginTime2(1L);
                operateLoginService.updateUpperByKey("", companypermit);
            }
        }
        return success;
    }

    /**
     * 车辆经营下线接口
     */
    public boolean operateLogout() {
        String url = "/operate/logout";
        String method = "operateLogout";
        JSONArray jsonArray = new JSONArray();

        OperateLogout query = new OperateLogout();
        query.setLogoutTime2(0L);
        List<OperateLogout> list = operateLogoutService.selectListUpper(null, query);
        logger.error("查询到车辆经营下线接口上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            OperateLogout companypermit = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("LicenseId", companypermit.getLicenseId());
            jsonObject.put("VehicleNo", companypermit.getVehicleNo());
            jsonObject.put("LogoutTime", companypermit.getLogoutTime());
            jsonObject.put("Longitude", companypermit.getLongitude());
            jsonObject.put("Latitude", companypermit.getLatitude());
            jsonObject.put("Encrypt", companypermit.getEncrypt());
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，车辆经营下线接口为已上传");
            for (int i = 0; i < list.size(); i++) {
                OperateLogout companypermit = list.get(i);
                companypermit.setLogoutTime2(1L);
                operateLogoutService.updateUpperByKey("", companypermit);
            }
        }
        return success;
    }

    /**
     * 经营出发
     */
    public boolean operateDepart() {
        String url = "/operate/depart";
        String method = "operateDepart";
        JSONArray jsonArray = new JSONArray();

        OperateDepart query = new OperateDepart();
        query.setDepTime2(0L);
        List<OperateDepart> list = operateDepartService.selectListUpper(null, query);
        logger.error("查询到经营出发接口上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            OperateDepart companypermit = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("OrderId", companypermit.getOrderId());
            jsonObject.put("LicenseId", companypermit.getLicenseId());
            jsonObject.put("VehicleNo", companypermit.getVehicleNo());
            jsonObject.put("FareType", companypermit.getFareType());
            jsonObject.put("DepLongitude", companypermit.getDepLongitude());
            jsonObject.put("DepLatitude", companypermit.getDepLatitude());
            jsonObject.put("Encrypt", companypermit.getEncrypt());
            jsonObject.put("DepTime", companypermit.getDepTime());
            jsonObject.put("WaitMile", companypermit.getWaitMile());
            jsonObject.put("WaitTime", companypermit.getWaitTime());
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，经营出发接口为已上传");
            for (int i = 0; i < list.size(); i++) {
                OperateDepart companypermit = list.get(i);
                companypermit.setDepTime2(1L);
                operateDepartService.updateUpperByKey("", companypermit);
            }
        }
        return success;
    }

    /**
     * 经营到达接口
     */
    public boolean operateArrive() {
        String url = "/operate/arrive";
        String method = "operateArrive";
        JSONArray jsonArray = new JSONArray();

        OperateArrive query = new OperateArrive();
        query.setDestTime2(0L);
        List<OperateArrive> list = operateArriveService.selectListUpper(null, query);
        logger.error("查询到经营到达接口上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            OperateArrive companypermit = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("OrderId", companypermit.getOrderId());
            jsonObject.put("DestLongitude", companypermit.getDestLongitude());
            jsonObject.put("DestLatitude", companypermit.getDestLatitude());
            jsonObject.put("Encrypt", companypermit.getEncrypt());
            jsonObject.put("DestTime", companypermit.getDestTime());
            jsonObject.put("DriveMile", companypermit.getDriveMile());
            jsonObject.put("DriveTime", companypermit.getDriveTime());
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，经营到达接口为已上传");
            for (int i = 0; i < list.size(); i++) {
                OperateArrive companypermit = list.get(i);
                companypermit.setDestTime2(1L);
                operateArriveService.updateUpperByKey("", companypermit);
            }
        }
        return success;
    }


    /**
     * 经营支付接口
     */
    public boolean operatePay() {
        String url = "/operate/pay";
        String method = "operatePay";
        JSONArray jsonArray = new JSONArray();

        OperatePay query = new OperatePay();
        query.setOrderMatchTime2(0L);
        List<OperatePay> list = operatePayService.selectListUpper(null, query);
        logger.error("查询到经营支付接口上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            OperatePay companypermit = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("OrderId", companypermit.getOrderId());
            jsonObject.put("OnArea", companypermit.getOnArea());
            jsonObject.put("DriverName", companypermit.getDriverName());
            jsonObject.put("LicenseId", companypermit.getLicenseId());
            jsonObject.put("FareType", companypermit.getFareType());
            jsonObject.put("VehicleNo", companypermit.getVehicleNo());
            jsonObject.put("BookDepTime", companypermit.getBookDepTime());
            jsonObject.put("WaitTime", companypermit.getWaitTime());
            jsonObject.put("DepLongitude", companypermit.getDepLongitude());
            jsonObject.put("DepArea", companypermit.getDepArea());
            jsonObject.put("DepTime", companypermit.getDepTime());
            jsonObject.put("DestLongitude", companypermit.getDestLongitude());
            jsonObject.put("DestLatitude", companypermit.getDestLatitude());
            jsonObject.put("DestArea", companypermit.getDestArea());
            jsonObject.put("DestTime", companypermit.getDestTime());
            jsonObject.put("BookModel", companypermit.getBookModel());
            jsonObject.put("Model", companypermit.getModel());
            jsonObject.put("DriveMile", companypermit.getDriveMile());
            jsonObject.put("DriveTime", companypermit.getDriveTime());
            jsonObject.put("WaitMile", companypermit.getWaitMile());
            jsonObject.put("FactPrice", companypermit.getFactPrice());
            jsonObject.put("Price", companypermit.getPrice());
            jsonObject.put("CashPrice", companypermit.getCashPrice());
            jsonObject.put("LineName", companypermit.getLineName());
            jsonObject.put("LinePrice", companypermit.getLinePrice());
            jsonObject.put("PosName", companypermit.getPosName());
            jsonObject.put("PosPrice", companypermit.getPosPrice());
            jsonObject.put("BenfitPrice", companypermit.getBenfitPrice());
            jsonObject.put("BookTip", companypermit.getBookTip());
            jsonObject.put("PassengerTip", companypermit.getPassengerTip());
            jsonObject.put("PeakUpPrice", companypermit.getPeakUpPrice());
            jsonObject.put("NightUpPrice", companypermit.getNightUpPrice());
            jsonObject.put("FarUpPrice", companypermit.getFarUpPrice());
            jsonObject.put("OtherUpPrice", companypermit.getOtherUpPrice());
            jsonObject.put("PayState", companypermit.getPayState());
            jsonObject.put("PayTime", companypermit.getPayTime());
            jsonObject.put("OrderMatchTime", companypermit.getOrderMatchTime());
            jsonObject.put("InvoiceStatus", companypermit.getInvoiceStatus());
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，经营支付接口为已上传");
            for (int i = 0; i < list.size(); i++) {
                OperatePay companypermit = list.get(i);
                companypermit.setOrderMatchTime2(1L);
                operatePayService.updateUpperByKey("", companypermit);
            }
        }
        return success;
    }

    /**
     * 驾驶员定位信息接口
     */
    public boolean positionDriver() {
        String url = "/operate/driver";
        String method = "positionDriver";
        JSONArray jsonArray = new JSONArray();

        PositionDriver query = new PositionDriver();
        query.setPositionTime2(0L);
        List<PositionDriver> list = positionDriverService.selectListUpper(null, query);
        logger.error("查询到驾驶员定位信息接口上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            PositionDriver companypermit = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("LicenseId", companypermit.getLicenseId());

            jsonObject.put("DriverRegionCode", companypermit.getDriverRegionCode());
            jsonObject.put("VehicleNo", companypermit.getVehicleNo());
            jsonObject.put("Encrypt", companypermit.getEncrypt());
            jsonObject.put("PositionTime", companypermit.getPositionTime());
            jsonObject.put("Longitude", tranDouble(companypermit.getLongitude()));
            jsonObject.put("Latitude", tranDouble(companypermit.getLatitude()));
            jsonObject.put("Encrypt", companypermit.getEncrypt());
                /*jsonObject.put("Direction", companypermit.getDirection());
                jsonObject.put("Elevation", companypermit.getElevation());
                jsonObject.put("Speed", companypermit.getSpeed());
                jsonObject.put("BizStatus", companypermit.getBizStatus());*/
            jsonObject.put("OrderId", companypermit.getOrderId());
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，驾驶员定位信息接口为已上传");
            for (int i = 0; i < list.size(); i++) {
                PositionDriver companypermit = list.get(i);
                companypermit.setPositionTime2(1L);
                positionDriverService.updateUpperByKey("", companypermit);
            }
        }
        return success;
    }

    /**
     * 车辆定位信息接口
     */
    public boolean positionVehicle() {
        String url = "/operate/vehicle";
        String method = "positionVehicle";
        JSONArray jsonArray = new JSONArray();

        PositionVehicle query = new PositionVehicle();
        query.setPositionTime2(0L);
        List<PositionVehicle> list = positionVehicleService.selectListUpper(null, query);
        logger.error("查询到车辆定位信息接口接口上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            PositionVehicle companypermit = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("VehicleNo", companypermit.getVehicleNo());
            jsonObject.put("VehicleRegionCode", companypermit.getVehicleRegionCode());
            jsonObject.put("PositionTime", companypermit.getPositionTime());
            jsonObject.put("Longitude", tranDouble(companypermit.getLongitude()));
            jsonObject.put("Latitude", tranDouble(companypermit.getLatitude()));
            jsonObject.put("Encrypt", companypermit.getEncrypt());
                /*jsonObject.put("Direction", companypermit.getDirection());
                jsonObject.put("Elevation", companypermit.getElevation());
                jsonObject.put("Speed", companypermit.getSpeed());
                jsonObject.put("BizStatus", companypermit.getBizStatus());
                jsonObject.put("WarnStatus", companypermit.getWarnStatus());
                jsonObject.put("VehStatus", companypermit.getVehStatus());
                jsonObject.put("Mileage", companypermit.getMileage());*/
            jsonObject.put("OrderId", companypermit.getOrderId());
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，车辆定位信息接口为已上传");
            for (int i = 0; i < list.size(); i++) {
                PositionVehicle companypermit = list.get(i);
                companypermit.setPositionTime2(1L);
                positionVehicleService.updateUpperByKey("", companypermit);
            }
        }
        return success;
    }

    /**
     * 乘客评价信息
     */
    public boolean ratedPassenger() {
        String url = "/rated/passenger";
        String method = "ratedPassenger";
        JSONArray jsonArray = new JSONArray();

        RatedPassenger query = new RatedPassenger();
        query.setEvaluateTime2(0L);
        List<RatedPassenger> list = ratedPassengerService.selectListUpper(null, query);
        logger.error("查询到乘客评价信息接口上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            RatedPassenger companypermit = list.get(i);
            //for (RatedPassenger companypermit : list) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("OrderId", companypermit.getOrderId());
            jsonObject.put("EvaluateTime", companypermit.getEvaluateTime());
            jsonObject.put("ServiceScore", companypermit.getServiceScore());
            jsonObject.put("DriverScore", companypermit.getDriverScore());
            jsonObject.put("VehicleScore", companypermit.getVehicleScore());
            jsonObject.put("Detail", companypermit.getDetail());

            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，乘客评价信息接口为已上传");
            for (int i = 0; i < list.size(); i++) {
                RatedPassenger companypermit = list.get(i);
                companypermit.setEvaluateTime2(1L);
                ratedPassengerService.updateUpperByKey("", companypermit);
            }
        }
        return success;
    }

    /**
     * 乘客投诉信息
     */
    public boolean ratedPassengerComplaint() {
        String url = "/rated/passengercomplaint";
        String method = "ratedPassengerComplaint";
        JSONArray jsonArray = new JSONArray();

        RatedPassengercomplaint query = new RatedPassengercomplaint();
        query.setComplaintTime2(0L);
        List<RatedPassengercomplaint> list = ratedPassengercomplaintService.selectListUpper(null, query);
        logger.error("查询到乘客投诉信息接口上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            RatedPassengercomplaint companypermit = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("OrderId", companypermit.getOrderId());
            jsonObject.put("ComplaintTime", companypermit.getComplaintTime());
            jsonObject.put("Detail", companypermit.getDetail());
            jsonObject.put("Result", companypermit.getResult());
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，乘客投诉信息接口为已上传");
            for (int i = 0; i < list.size(); i++) {
                RatedPassengercomplaint companypermit = list.get(i);
                companypermit.setComplaintTime2(1L);
                ratedPassengercomplaintService.updateUpperByKey("", companypermit);
            }
        }
        return success;
    }


    /**
     * 驾驶员处罚信息
     */
    public boolean ratedDriverPunish() {
        String url = "/rated/driverpunish";
        String method = "ratedDriverPunish";
        JSONArray jsonArray = new JSONArray();

        RatedDriverpunish query = new RatedDriverpunish();
        query.setPunishTime2(0L);
        List<RatedDriverpunish> list = ratedDriverpunishService.selectListUpper(null, query);
        logger.error("查询到驾驶员处罚信息接口上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            RatedDriverpunish companypermit = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("LicenseId", companypermit.getLicenseId());
            jsonObject.put("PunishTime", companypermit.getPunishTime());
            jsonObject.put("PunishReason", companypermit.getPunishReason());
            jsonObject.put("PunishResult", companypermit.getPunishResult());
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，驾驶员处罚信息接口为已上传");
            for (int i = 0; i < list.size(); i++) {
                RatedDriverpunish companypermit = list.get(i);
                companypermit.setPunishTime2(1L);
                ratedDriverpunishService.updateUpperByKey("", companypermit);
            }
        }
        return success;
    }

    /**
     * 驾驶员信誉信息
     */
    public boolean ratedDriver() {
        String url = "/rated/driver";
        String method = "ratedDriver";
        JSONArray jsonArray = new JSONArray();

        RatedDriver query = new RatedDriver();
        query.setTestDate2(0L);
        List<RatedDriver> list = ratedDriverService.selectListUpper(null, query);
        logger.error("查询到驾驶员信誉信息接口上报数量为：" + list.size());
        for (int i = 0; i < list.size(); i++) {
            RatedDriver companypermit = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("CompanyId", companypermit.getCompanyId());
            jsonObject.put("LicenseId", companypermit.getLicenseId());
            jsonObject.put("Level", companypermit.getLevel());
            jsonObject.put("TestDate", companypermit.getTestDate());
            jsonObject.put("TestDepartment", companypermit.getTestDepartment());
            jsonArray.add(jsonObject);
        }
        boolean success = pushData(jsonArray, url, method);
        if (success) {
            logger.error("上传成功，驾驶员信誉信息接口为已上传");
            for (int i = 0; i < list.size(); i++) {
                RatedDriver companypermit = list.get(i);
                companypermit.setTestDate2(1L);
                ratedDriverService.updateUpperByKey("", companypermit);
            }
        }
        return success;
    }


    private boolean pushData(JSONArray jsonArray, String url, String method) {
        if (jsonArray.size() <= 0) {
            return true;
        }
        JSONObject reqObject = new JSONObject();
        reqObject.put("CompanyId", "5201HDCX8779");
        reqObject.put("Source", "0");
        reqObject.put("IPCType", method);
        reqObject.put(method, jsonArray);

        String json = JSON.toJSONString(reqObject);
        logger.error("list=" + json);
        //String sign = SignUtil.encrypt(json, 1, "ldk@api");
        Map<String, String> headers = new HashMap<String, String>();
        //headers.put("sign", sign);
        headers.put("Content—Type", "application/json");
        String response = HttpUtil.post(posturl + url, json, headers);
        logger.error("-----url=" + url + ",method=" + method + ",response=" + response);
        if (!TextUtils.isEmpty(response) && response.contains("ok")) {
            return true;
        }
        return false;
    }

    private Long tranDouble(Double value) {
        if (value == null) {
            return 0L;
        }
        long v = Long.parseLong(value.toString().replace(".", ""));
        return v;
    }


    public static boolean LAST_FLOW_CHECK_DONE = true;

    public void pushVehicleToSys() {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    logger.error("开始执行定时推送任务");
                    JSONArray jsonArray = new JSONArray();
                    String url = "/baseinfo/vehicle";
                    String method = "baseinfoVehicle";
                    Vehicle query = new Vehicle();
                    query.setUploadFlag(0);
                    List<Vehicle> list = vehicleService.selectList(null, query);
                    logger.error("list=" + JSON.toJSONString(list));
                    List<PlatformDriver> driverlist = platformDriverService.selectAll(null);
                    for (int i = 0; i < list.size(); i++) {
                        Vehicle companypermit = list.get(i);
                        //if("贵AD71013".equals(companypermit.getVehicleNo())){
                        JSONObject jsonObject = new JSONObject();
                        jsonObject.put("CompanyId", companypermit.getCompanyId());
                        jsonObject.put("Address", companypermit.getAddress());
                        jsonObject.put("VehicleNo", companypermit.getVehicleNo());
                        jsonObject.put("PlateColor", companypermit.getPlateColor());
                        jsonObject.put("Seats", companypermit.getSeats());
                        jsonObject.put("Brand", companypermit.getBrand());
                        jsonObject.put("Model", companypermit.getModel());
                        jsonObject.put("VehicleType", companypermit.getVehicleType());
                        jsonObject.put("OwnerName", companypermit.getOwnerName());
                        jsonObject.put("VehicleColor", companypermit.getVehicleColor());
                        jsonObject.put("EngineId", companypermit.getEngineId());
                        jsonObject.put("VIN", companypermit.getVIN());
                        jsonObject.put("CertifyDateA", companypermit.getCertifyDateA());
                        jsonObject.put("FuelType", companypermit.getFuelType());
                        jsonObject.put("EngineDisplace", companypermit.getEngineDisplace());
                        //jsonObject.put("PhotoId", companypermit.getPhotoId());
                        //jsonObject.put("Certificate", companypermit.getCertificate());
                        jsonObject.put("TransAgency", companypermit.getTransAgency());
                        jsonObject.put("TransArea", companypermit.getTransArea());
                        jsonObject.put("TransDateStart", companypermit.getTransDateStart());
                        jsonObject.put("CertifyDateB", companypermit.getCertifyDateB());
                        jsonObject.put("FixState", companypermit.getFixState());
                        //jsonObject.put("NextFixDate", companypermit.getNextFixDate());
                        jsonObject.put("CheckState", companypermit.getCheckState());
                        jsonObject.put("FeePrintId", companypermit.getFeePrintId());
                        jsonObject.put("GPSBrand", companypermit.getGPSBrand());
                        jsonObject.put("GPSModel", companypermit.getGPSModel());
                        jsonObject.put("GPSIMEI", companypermit.getGPSIMEI());
                        jsonObject.put("GPSInstallDate", companypermit.getGPSInstallDate());
                        jsonObject.put("RegisterDate", companypermit.getRegisterDate());
                        jsonObject.put("CommercialType", companypermit.getCommercialType());
                        jsonObject.put("FareType", companypermit.getFareType());
                        jsonObject.put("State", companypermit.getState());
                        jsonObject.put("Flag", companypermit.getFlag());
                        jsonObject.put("UpdateTime", DateUtil.DatetoString(new Date(), "yyyyMMddHHmmss"));
                        jsonArray.add(jsonObject);
                        // }
                        putToGJ(companypermit, driverlist);
                    }
                    /*if (jsonArray.size() > 0) {
                        JSONObject reqObject = new JSONObject();
                        reqObject.put("CompanyId", "5201HDCX8779");
                        reqObject.put("Source", "0");
                        reqObject.put("IPCType", method);
                        reqObject.put(method, jsonArray);

                        String json = JSON.toJSONString(reqObject);
                        System.out.println("json=" + json);
                        //String sign = SignUtil.encrypt(json, 1, "ldk@api");
                        Map<String, String> headers = new HashMap<String, String>();
                        //headers.put("sign", sign);
                        headers.put("Content—Type", "application/json");

                        String response = HttpUtil.post(posturl + url, json, headers);
                        System.out.print("response=" + response);
                        if (!TextUtils.isEmpty(response) && response.contains("ok")) {
                            for (int i = 0; i < list.size(); i++) {
                                Vehicle companypermit = list.get(i);
                                companypermit.setUploadFlag(1);
                                vehicleService.updateByKey("", companypermit);
                            }
                        }
                    } else {
                        logger.error("暂无推送的车辆信息");
                    }*/
                } catch (Exception e) {
                    logger.error(e.getMessage());
                }
                LAST_FLOW_CHECK_DONE = true;
            }
        });
        if (LAST_FLOW_CHECK_DONE) {
            t1.start();
            LAST_FLOW_CHECK_DONE = false;
        } else {
            logger.error("-考核信息计算状态-上一批次未完成，已忽略本次计算");
        }
    }

    public String posturlGJ = "http://222.85.224.5:9080/gjza/imp/net/";
    public String authtoken = "ed03a2cd3d67420b9111c8c1a8710bd3";

    public void putToGJ(Vehicle companypermit, List<PlatformDriver> driverlist) {
        try {
            JSONArray jsonArrayGj = new JSONArray();
            JSONObject jsonObjectGJ = new JSONObject();
            jsonObjectGJ.put("plateNumber", companypermit.getVehicleNo());
            jsonObjectGJ.put("carType", 0);
            jsonObjectGJ.put("truckColor", companypermit.getVehicleColor());
            jsonObjectGJ.put("brand", companypermit.getBrand());
            jsonObjectGJ.put("plateModel", companypermit.getModel());
            jsonObjectGJ.put("fuelType", "汽油");
            jsonObjectGJ.put("isDel", "0");

            JSONArray driverArray = new JSONArray();
            JSONObject jsonObject1 = getDriverInfo(driverlist, companypermit.getDriverPhone());
            if (jsonObject1 != null && !TextUtils.isEmpty(jsonObject1.getString("phone"))) {
                driverArray.add(jsonObject1);
            }
            JSONArray equipsArray = new JSONArray();
            JSONObject jsonObject2 = new JSONObject();
            jsonObject2.put("equipName", "巡逻鹰GPS");
            jsonObject2.put("equipStatus", "正常");
            jsonObject2.put("installTime", companypermit.getCertifyDateA());
            jsonObject2.put("isDel", "0");
            equipsArray.add(jsonObject2);

            jsonObjectGJ.put("drivers", driverArray);
            jsonObjectGJ.put("equips", equipsArray);

            jsonArrayGj.add(jsonObjectGJ);

            String json = JSON.toJSONString(jsonArrayGj);

            Map<String, String> headers = new HashMap<String, String>();
            headers.put("X-Authorization", authtoken);
            headers.put("Content-Type", "application/json");

            String decode = URLEncoder.encode(json, "UTF-8");
            String urlGJ = posturlGJ + "postTransitData?transits=" + decode;
            String response = HttpUtil.post(urlGJ, null, headers);
            System.out.println("公交公司返回,response=" + response);
            if (!response.contains("1000")) {
                System.out.print("json=" + json);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public JSONObject getDriverInfo(List<PlatformDriver> driverList, String phoneNo) {
        JSONObject jsonObject = new JSONObject();
        for (PlatformDriver driver : driverList) {
            if (driver.getDriverPhone() != null && phoneNo != null && driver.getDriverPhone().equals(phoneNo)) {
                jsonObject.put("realName", driver.getDriverName());
                jsonObject.put("identityId", driver.getLicenseId());
                jsonObject.put("phone", driver.getDriverPhone());
                jsonObject.put("sex", driver.getDriverGender());
                jsonObject.put("dayOfBirth", driver.getDriverBirthday());
                jsonObject.put("placeOfOrigin", "贵州" + driver.getContractCompany());
                jsonObject.put("homePlace", driver.getDriverContactAddress());
                jsonObject.put("hasLocal", "1");
                jsonObject.put("isDel", "0");
            }
        }
        return jsonObject;
    }
}
